WITH user_ids AS
  (SELECT t.user_id
  FROM eh_mobile_phone_bind t
  WHERE t.MOBILE_PHONE = :code
  AND (Sysdate BETWEEN t.begin_date AND t.end_date)
  UNION
  SELECT t.id AS user_id FROM c1_user t WHERE t.code = :code
  )
SELECT T.*,
  (
  CASE
    WHEN (SYSDATE BETWEEN NVL(T.BEGIN_DATE, SYSDATE) AND NVL(T.END_DATE, SYSDATE))
    THEN '1'
    ELSE '2'
  END) AS valid_code
FROM c1_user t
WHERE EXISTS
  (SELECT 1 FROM user_ids i WHERE i.user_id = t.id
  )